package com.yizhilu.os.common.intercepter;

import com.yizhilu.os.core.controller.MemLoginUtils;
import com.yizhilu.os.core.util.ObjectUtils;
import com.yizhilu.os.core.util.web.WebUtils;
import java.util.Arrays;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.yizhilu.os.core.common.intercepter.LoggerFilter;

public class LoggerKuajidaoFilter extends LoggerFilter
{
  private static Logger logger = LoggerFactory.getLogger(LoggerKuajidaoFilter.class);
  private String[] excludeUrls;
  
  public String[] getExcludeUrls()
  {
    return this.excludeUrls;
  }
  
  public void setExcludeUrls(String[] excludeUrls)
  {
    this.excludeUrls = excludeUrls;
  }
  
  public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
    throws Exception
  {
    super.afterCompletion(request, response, handler, ex);
  }
  
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
    throws Exception
  {
    super.postHandle(request, response, handler, modelAndView);
  }
  
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws Exception
  {
    String ip = WebUtils.getIpAddr(request);
    
    String path = request.getContextPath() + request.getServletPath();
    if (!ObjectUtils.isNull(this.excludeUrls)) {
      for (String url : this.excludeUrls) {
        if (path.contains(url)) {
          return true;
        }
      }
    }
    StringBuffer buffer = new StringBuffer("");
    Enumeration<String> enume = request.getParameterNames();
    while (enume.hasMoreElements())
    {
      String key = (String)enume.nextElement();
      String[] value = request.getParameterValues(key);
      if (buffer.toString().length() > 0) {
        buffer.append("  ");
      }
      buffer.append(key).append("=").append(Arrays.toString(value));
    }
    logger.info("+++user_access_log,ip=" + ip + ",uid:" + MemLoginUtils.getLoginUserId(request) + ",url=" + path + ",parameter=" + buffer);
    return true;
  }
}



/* Location:           C:\Users\Administrator\Desktop\springmvc-core-2.5.jar

 * Qualified Name:     com.yizhilu.os.core.common.intercepter.LoggerFilter

 * JD-Core Version:    0.7.0.1

 */